package Leetcode.DayTest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Test_25_3_6 {

    public List<String> test(double length, double width, double height, double weight) {
        // 转换单位：cm -> in, kg -> lb
        double lengthIn = cmToIn(length);
        double widthIn = cmToIn(width);
        double heightIn = cmToIn(height);
        double weightLb = kgToLb(weight);

        // 计算围长
        double[] dimensions = {lengthIn, widthIn, heightIn};
        Arrays.sort(dimensions); // 排序：最短边、次长边、最长边
        double girth = dimensions[2] + (dimensions[1] + dimensions[0]) * 2;

        // 计算体积重
        double volumetricWeight = Math.ceil((dimensions[2] * dimensions[1] * dimensions[0]) / 250);

        // 计算实重
        double actualWeight = Math.max(weightLb, volumetricWeight);

        // 判断类型
        List<String> result = new ArrayList<>();
        // OUT_SPACE 优先级最高，直接返回
        // 1. 判断 OUT_SPACE
        if (actualWeight > 150 || dimensions[2] > 108 || girth > 165) {
            result.add("OUT_SPACE");
            return result;
        }

        // 2. 判断 OVERSIZE
        if ((girth > 130 && girth <= 165) || (dimensions[2] >= 96 && dimensions[2] <= 108)) {
            result.add("OVERSIZE");
            return result; // OVERSIZE 优先级高于 AHS
        }

        // 3. 判断 AHS
        boolean isAHSWeight = actualWeight > 50 && actualWeight <= 150;
        boolean isAHSSize = girth > 105 || (dimensions[2] >= 48 && dimensions[2] < 108) || dimensions[1] >= 30;

        if (isAHSWeight) {
            result.add("AHS-WEIGHT");
        }
        if (isAHSSize) {
            result.add("AHS-SIZE");
        }

        return result;
    }

    // 厘米转英寸（向上取整）
    private double cmToIn(double cm) {
        return Math.ceil(cm / 2.54);
    }

    // 千克转磅（向上取整）
    private double kgToLb(double kg) {
        return Math.ceil(kg / 0.454);
    }

    public static void main(String[] args) {
        Test_25_3_6 obj = new Test_25_3_6();

        // 测试用例
        System.out.println(obj.test(68, 70, 60, 23));
        System.out.println(obj.test(114.5, 42, 26, 47.5));
        System.out.println(obj.test(162, 60, 11, 14));
        System.out.println(obj.test(113, 64, 42.5, 35.85));
        System.out.println(obj.test(114.5, 17, 51.5, 16.5));
    }
}